package com.qfjy.controller.example4;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName ScanPayController
 * @Description TODO
 * @Author guoweixin
 * @Date 2022/11/22
 * @Version 1.0
 */
@Controller
@Slf4j
@RequestMapping("scan")
@ResponseBody
public class ScanPayController {


    @Autowired
    private AmqpTemplate amqpTemplate;
    /**
     * 用户扫描支付，根据用户的不同条件，完成不同的服务器支付（不同的队列操作）
     */
    @GetMapping("sendPay")
    public String sendPay(HttpServletRequest request){

        // 标识 支付宝、微信
        String flag= request.getParameter("flag");
        // 操作金额
        double balance=Double.parseDouble(request.getParameter("balance"));

        /**
         * String exchange, String routingKey, Object object
         * param1:交换机名称
         * param2: 路由KEY
         * param3:传输的对象（数据载体）
         */
        amqpTemplate.convertAndSend("scanPayDirectExchange",flag,balance);


        return flag+"转帐成功"+balance;

    }
}
